<?php

/**
 * This is the model class for table "repositories".
 *
 * The followings are the available columns in table 'repositories':
 * @property integer $id
 * @property integer $project_id
 * @property string $url
 * @property string $login
 * @property string $password
 * @property string $root_url
 * @property string $type
 * @property string $path_encoding
 * @property string $log_encoding
 * @property string $extra_info
 * @property string $identifier
 * @property integer $is_default
 *
 * The followings are the available model relations:
 * @property Changesets[] $changesets
 * @property Project $project
 */
class Repository extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Repositories the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'repositories';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('project_id, is_default', 'numerical', 'integerOnly'=>true),
            array('url, password, root_url, type, identifier', 'length', 'max'=>255),
            array('login', 'length', 'max'=>60),
            array('path_encoding, log_encoding', 'length', 'max'=>64),
            array('extra_info', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, project_id, url, login, password, root_url, type, path_encoding, log_encoding, extra_info, identifier, is_default', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'changesets' => array(self::HAS_MANY, 'Changeset', 'repository_id'),
            'project' => array(self::BELONGS_TO, 'Project', 'project_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'project_id' => 'Project',
            'url' => 'Url',
            'login' => 'Login',
            'password' => 'Password',
            'root_url' => 'Root Url',
            'type' => 'Type',
            'path_encoding' => 'Path Encoding',
            'log_encoding' => 'Log Encoding',
            'extra_info' => 'Extra Info',
            'identifier' => 'Identifier',
            'is_default' => 'Is Default',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('project_id',$this->project_id);
        $criteria->compare('url',$this->url,true);
        $criteria->compare('login',$this->login,true);
        $criteria->compare('password',$this->password,true);
        $criteria->compare('root_url',$this->root_url,true);
        $criteria->compare('type',$this->type,true);
        $criteria->compare('path_encoding',$this->path_encoding,true);
        $criteria->compare('log_encoding',$this->log_encoding,true);
        $criteria->compare('extra_info',$this->extra_info,true);
        $criteria->compare('identifier',$this->identifier,true);
        $criteria->compare('is_default',$this->is_default);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}